using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using Toenda.TFL.Data;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Controls_ctrl_header : System.Web.UI.UserControl {
	private AccountProvider ap = new AccountProvider();

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		Account acc = null;

		//if(Session.Count > 0 && ap.CheckSessionExist(Session["Zappr"].ToString())) {
		if(Session.Count > 0 && Session["ZapprUserId"] != null) {
			acc = ap.GetAccount(Session["ZapprUserId"].ToString());
		}

		if(acc != null && acc.ID != "") {
			plcUserLinks.Visible = true;
			plcSignupLinks.Visible = false;

			plcTopmenu.Controls.Clear();
			plcTopmenuPublic.Controls.Clear();

			plcTopmenu.Controls.Add(LoadControl("ctrl_topmenu.ascx"));
			plcTopmenuPublic.Controls.Add(LoadControl("ctrl_topmenu_public.ascx"));

			lblUsertext.Text = GetLocalResourceObject("LoggedInAs").ToString()
				+ " " + acc.Username;

			panelSearch.CssClass = "headerSearchRightLoggedIn";
		}
		else {
			plcSignupLinks.Visible = true;
			plcUserLinks.Visible = false;

			plcTopmenu.Controls.Clear();
			plcTopmenuPublic.Controls.Clear();

			plcTopmenuPublic.Controls.Add(LoadControl("ctrl_topmenu_public.ascx"));
		}

		NameValueCollection sv = Request.ServerVariables;

		//plcTopmenu.Controls.Add(new LiteralControl(sv["URL"]));
		
		if(sv["URL"] == "/login.aspx"
		|| sv["URL"] == "/login.aspx"
		|| sv["URL"] == "/WebClient/login.aspx"
		|| sv["URL"] == "/WebClient/login.aspx") {
			plcSearch.Visible = false;
		}
		
		if(sv["URL"] == "/search.aspx"
		|| sv["URL"] == "/search.aspx"
		|| sv["URL"] == "/WebClient/search.aspx"
		|| sv["URL"] == "/WebClient/search.aspx") {
			plcSearch.Visible = false;
		}
	}

	/// <summary>
	/// btnSearch_Click
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void btnSearch_Click(object sender, EventArgs e) {
		Response.Redirect("~/search.aspx?q=" + txtSearch.Text.Trim());
	}
}
